define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'zhongzhuan/fenpei/feiyuassignkehu/index' + location.search,
                    add_url: 'zhongzhuan/fenpei/feiyuassignkehu/add',
//                    edit_url: 'zhongzhuan/fenpei/assignkehu/edit',
                    del_url: 'zhongzhuan/fenpei/feiyuassignkehu/del',
                    multi_url: 'zhongzhuan/fenpei/feiyuassignkehu/multi',
                    import_url: 'zhongzhuan/fenpei/feiyuassignkehu/import',
                    table: 'ec_assign_feiyu_kehu',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'name', title:'名称', operate: 'LIKE',searchable:false},
                        {field: 'count', title: '计划分配数', operate: 'LIKE',searchable:false},
                        {field: 'daituisong_count', title: '待推送', operate: 'LIKE',searchable:false},
                        {field: 'success_count', title: '推送成功', operate: 'LIKE',searchable:false},
                        {field: 'fail_count', title: '未推送', operate: 'LIKE',searchable:false},
//                        {field: 'auto_assign', title: '自动分配', searchList: {"0":__('auto_assign 0'),"1":__('auto_assign 1')}, formatter: Table.api.formatter.status},
                        {field: 'auto_assign', title: '自动分配', searchList: {"0":__('auto_assign 0'),"1":__('auto_assign 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                            formatter:Table.api.formatter.operate,
                            buttons: [
//                                {
//                                    name: 'detail',
//                                    text: '分配规则',
//                                    icon: 'fa fa-list',
//                                    classname: 'btn btn-info btn-xs btn-assign btn-dialog',
//                                    url: '/zQFZdrEgGv.php/zhongzhuan/fenpei/assignkehudetail/index',
////                                    extend: 'data-area=["90%","90%"]', //这是控制弹窗的弹出的尺寸
//                                    callback: function (data) {
//    //                                        table.bootstrapTable('refresh');
//    //                                        Layer.alert(JSON.stringify(data));
//                                    },
//                                    visible: function (row) {
//                                        return true;
//
//                                    }
//                                },                                
                                {
                                    name: 'modify',
                                    text: "编辑",
                                    icon: 'fa fa-pencil',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    url: '/zQFZdrEgGv.php/zhongzhuan/fenpei/feiyuassignkehu/edit',
                                    extend: 'data-area=["90%","90%"]', //这是控制弹窗的弹出的尺寸
                                    callback: function (data) {
    //                                        table.bootstrapTable('refresh');
    //                                        Layer.alert(JSON.stringify(data));
                                    },
                                    visible: function (row) {                                       
                                        return true;
                                    }
                                }                                
                                
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
